import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/phoneLogin',
    component: () => import('@/views/phoneLogin/login/login'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/food',
    name: 'Food',
    component: Layout,
    meta: { title: '蛋糕管理', icon: 'el-icon-bank-card' },
    children: [
      {
        path: 'foodlist',
        name: 'foodList',
        component: () => import('@/views/food/foodList'),
        meta: { title: '蛋糕列表' }
      },
      {
        path: 'addfood',
        name: 'addFood',
        component: () => import('@/views/food/addFood'),
        meta: { title: '添加蛋糕' }
      },
      {
        path: 'todayfood',
        name: 'todayFood',
        component: () => import('@/views/food/todayFood'),
        meta: { title: '今日推荐' }
      }
    ]
  },

  {
    path: '/category',
    name: 'Category',
    component: Layout,
    meta: { title: '蛋糕分类', icon: 'el-icon-goods' },
    children: [
      {
        path: 'catelist',
        name: 'cateList',
        component: () => import('@/views/category/cateList'),
        meta: { title: '蛋糕分类' }
      }
      // {
      //   path: 'addcate',
      //   name: 'addCate',
      //   component: () => import('@/views/category/addCate'),
      //   meta: { title: '添加分类' }
      // },

    ]
  },

  {
    path: '/order',
    name: 'Order',
    component: Layout,
    children: [{
      path: 'order',
      name: 'Order',
      component: () => import('@/views/order/orderList'),
      meta: { title: '订单管理', icon: 'dashboard' }
    }]
  },

  {
    path: '/comment',
    name: 'Comment',
    component: Layout,
    children: [{
      path: 'comment',
      name: 'Comment',
      component: () => import('@/views/comment/commentList'),
      meta: { title: '店铺评论', icon: 'el-icon-s-comment' }
    }]
  },

  {
    path: '/shop',
    name: 'Shop',
    component: Layout,
    children: [{
      path: 'shopdetail',
      name: 'shopDetail',
      component: () => import('@/views/shop/shopDetail'),
      meta: { title: '修改店铺信息', icon: 'el-icon-s-shop' }
    }]
  },
  {
    path: '/admincomment',
    name: 'AdminComment',
    component: Layout,
    children: [{
      path: 'admincomment',
      name: 'adminComment',
      component: () => import('@/views/admincomment/adminComment'),
      meta: { title: '管理员评论列表', icon: 'dashboard' }
    }]
  },

  {
    path: '/user',
    name: 'User',
    component: Layout,
    children: [{
      path: 'adduser',
      name: 'addUser',
      component: () => import('@/views/user/addUser'),
      meta: { title: '管理员注册店主账号', icon: 'dashboard' }
    }]
  },

  {
    path: '/shop',
    name: 'Shop',
    component: Layout,
    meta: { title: '管理员店铺管理', icon: 'dashboard' },
    children: [
      // {
      // path: 'vshopdetail',
      // name: 'vshopDetail',
      // component: () => import('@/views/shop/vshopDetail'),
      // meta: { title: '管理员修改店铺详情页' },
      // },
      {
        path: 'vshoplist',
        name: 'vshopList',
        component: () => import('@/views/shop/vshopList'),
        meta: { title: '管理员店铺列表' }
      }
    ]
  },
  {
    path: '/liaotian/webscoketServer/lm',
    name: 'lm',
    component: Layout,
    children: [{
      path: 'lm',
      name: 'lm',
      component: () => import('@/views/liaotian/webscoketServer/lm.vue'),
      meta: { title: '聊天管理', icon: 'el-icon-chat-dot-round' }
    }]
  },
  {
    path: '/gaode/map/map',
    name: 'map',
    component: Layout,
    children: [{
      path: 'map',
      name: 'Map',
      component: () => import('@/views/gaode/map/map.vue'),
      meta: { title: '地图管理', icon: 'el-icon-s-flag' }
    }]
  },
  {
    path: '/adminGoods/goods/goods',
    name: 'goods',
    component: Layout,
    children: [{
      path: 'goods',
      name: 'goods',
      component: () => import('@/views/adminGoods/goods/goods.vue'),
      meta: { title: '进料管理', icon: 'el-icon-printer' }
    }]
  },
  {
    path: '/shopGoods/shopGoods/index',
    name: 'index',
    component: Layout,
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/shopGoods/shopGoods/index.vue'),
      meta: { title: '进货管理', icon: 'el-icon-printer' }
    }]
  },
  {
    path: '/shopOrder/order/index',
    name: 'index',
    component: Layout,
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/shopOrder/order/index.vue'),
      meta: { title: '物料订单管理', icon: 'el-icon-printer' }
    }]
  },
  {
    path: '/usershopOrder/usershopOrder/index',
    name: 'index',
    component: Layout,
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/usershopOrder/usershopOrder/index.vue'),
      meta: { title: '物料订单管理', icon: 'el-icon-printer' }
    }]
  },
  {
    path: '/daka/dakaviews/daka',
    name: 'daka',
    component: Layout,
    children: [{
      path: 'daka',
      name: 'daka',
      component: () => import('@/views/daka/dakeviews/daka.vue'),
      meta: { title: '定位打卡', icon: 'el-icon-s-flag' }
    }]
  },
  {
    path: '/adminGoods/goods/goods',
    name: 'goods',
    component: Layout,
    children: [{
      path: 'goods',
      name: 'goods',
      component: () => import('@/views/adminGoods/goods/goods.vue'),
      meta: { title: '原料管理', icon: 'el-icon-printer' }
    }]
  },
  {
    path: '/sign/signDaka/sign',
    name: 'sign',
    component: Layout,
    children: [{
      path: 'sign',
      name: 'sign',
      component: () => import('@/views/sign/signDaka/sign.vue'),
      meta: { title: '打卡管理', icon: 'el-icon-printer' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

export const userRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/phoneLogin',
    component: () => import('@/views/phoneLogin/login/login'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },

  {
    path: '/food',
    name: 'Food',
    component: Layout,
    meta: { title: '蛋糕管理', icon: 'el-icon-goods' },
    children: [
      {
        path: 'foodlist',
        name: 'foodList',
        component: () => import('@/views/food/foodList'),
        meta: { title: '蛋糕列表' }
      }
      // {
      //   path: 'addfood',
      //   name: 'addFood',
      //   component: () => import('@/views/food/addFood'),
      //   meta: { title: '添加菜品' }
      // },
      // {
      //   path: 'todayfood',
      //   name: 'todayFood',
      //   component: () => import('@/views/food/todayFood'),
      //   meta: { title: '今日推荐' }
      // },
    ]
  },

  {
    path: '/category',
    name: 'Category',
    component: Layout,
    meta: { title: '蛋糕分类', icon: 'el-icon-goods' },
    children: [
      {
        path: 'catelist',
        name: 'cateList',
        component: () => import('@/views/category/cateList'),
        meta: { title: '蛋糕分类' }
      }
      // {
      //   path: 'addcate',
      //   name: 'addCate',
      //   component: () => import('@/views/category/addCate'),
      //   meta: { title: '添加分类' }
      // },

    ]
  },

  {
    path: '/order',
    name: 'Order',
    component: Layout,
    children: [{
      path: 'order',
      name: 'Order',
      component: () => import('@/views/order/orderList'),
      meta: { title: '订单管理', icon: 'dashboard' }
    }]
  },

  {
    path: '/comment',
    name: 'Comment',
    component: Layout,
    children: [{
      path: 'comment',
      name: 'Comment',
      component: () => import('@/views/comment/commentList'),
      meta: { title: '店铺评论', icon: 'el-icon-s-comment' }
    }]
  },

  {
    path: '/shop',
    name: 'Shop',
    component: Layout,
    children: [{
      path: 'shopdetail',
      name: 'shopDetail',
      component: () => import('@/views/shop/shopDetail'),
      meta: { title: '修改店铺信息', icon: 'el-icon-s-shop' }
    }]
  },
  {
    path: '/liaotian/webscoketServer/lm',
    name: 'lm',
    component: Layout,
    children: [{
      path: 'lm',
      name: 'lm',
      component: () => import('@/views/liaotian/webscoketServer/lm.vue'),
      meta: { title: '聊天管理', icon: 'el-icon-chat-dot-round' }
    }]
  },
  {
    path: '/gaode/map/map',
    name: 'map',
    component: Layout,
    children: [{
      path: 'map',
      name: 'Map',
      component: () => import('@/views/gaode/map/map.vue'),
      meta: { title: '地图管理', icon: 'el-icon-s-flag' }
    }]
  },
  {
    path: '/shopGoods/shopGoods/index',
    name: 'index',
    component: Layout,
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/shopGoods/shopGoods/index.vue'),
      meta: { title: '进货管理', icon: 'el-icon-printer' }
    }]
  },
  {
    path: '/usershopOrder/usershopOrder/index',
    name: 'index',
    component: Layout,
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/usershopOrder/usershopOrder/index.vue'),
      meta: { title: '物料订单管理', icon: 'el-icon-printer' }
    }]
  },
  {
    path: '/daka/dakaviews/daka',
    name: 'daka',
    component: Layout,
    children: [{
      path: 'daka',
      name: 'daka',
      component: () => import('@/views/daka/dakeviews/daka.vue'),
      meta: { title: '定位打卡', icon: 'el-icon-s-flag' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

export const adminRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/phoneLogin',
    component: () => import('@/views/phoneLogin/login/login'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'el-icon-cold-drink' }
    }]
  },
  {
    path: '/admincomment',
    name: 'AdminComment',
    component: Layout,
    children: [{
      path: 'admincomment',
      name: 'adminComment',
      component: () => import('@/views/admincomment/adminComment'),
      meta: { title: '评论管理', icon: 'el-icon-chat-line-round' }
    }]
  },

  {
    path: '/user',
    name: 'User',
    component: Layout,
    children: [{
      path: 'adduser',
      name: 'addUser',
      component: () => import('@/views/user/addUser'),
      meta: { title: '注册管理', icon: 'user' }
    }]
  },

  {
    path: '/shop',
    name: 'Shop',
    component: Layout,
    meta: { title: '店铺管理', icon: 'table' },
    children: [
      // {
      // path: 'vshopdetail',
      // name: 'vshopDetail',
      // component: () => import('@/views/shop/vshopDetail'),
      // meta: { title: '管理员修改店铺详情页' },
      // },
      {
        path: 'vshoplist',
        name: 'vshopList',
        component: () => import('@/views/shop/vshopList'),
        meta: { title: '店铺列表' }
      }
    ]
  },
  {
    path: '/liaotian/webscoketServer/lm',
    name: 'lm',
    component: Layout,
    children: [{
      path: 'lm',
      name: 'lm',
      component: () => import('@/views/liaotian/webscoketServer/lm.vue'),
      meta: { title: '聊天管理', icon: 'el-icon-chat-dot-round' }
    }]
  },
  {
    path: '/gaode/map/map',
    name: 'map',
    component: Layout,
    children: [{
      path: 'map',
      name: 'Map',
      component: () => import('@/views/gaode/map/map.vue'),
      meta: { title: '地图管理', icon: 'el-icon-s-flag' }
    }]
  },
  {
    path: '/adminGoods/goods/goods',
    name: 'goods',
    component: Layout,
    children: [{
      path: 'goods',
      name: 'goods',
      component: () => import('@/views/adminGoods/goods/goods.vue'),
      meta: { title: '原料管理', icon: 'el-icon-printer' }
    }]
  },
  {
    path: '/shopOrder/order/index',
    name: 'index',
    component: Layout,
    children: [{
      path: 'index',
      name: 'index',
      component: () => import('@/views/shopOrder/order/index.vue'),
      meta: { title: '物料订单管理', icon: 'el-icon-printer' }
    }]
  },
  {
    path: '/sign/signDaka/sign',
    name: 'sign',
    component: Layout,
    children: [{
      path: 'sign',
      name: 'sign',
      component: () => import('@/views/sign/signDaka/sign.vue'),
      meta: { title: '打卡管理', icon: 'el-icon-printer' }
    }]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
